#include<vector>
#include<string>
using namespace std;

class Solution {
public:
    int minDeletionSize(vector<string>& A) {
        if (A.size() == 1) return 0;
        vector<bool> state(A.size(), false);
        int ans = 0;
        for (int i = 0; i < A[0].size(); ++i) {
            bool flag = true;
            for (int j = 0; j < A.size() - 1; ++j) {
                if (!state[j]&&A[j][i] > A[j + 1][i]) {
                    ++ans;
                    flag = false;
                    break;
                }
            }
            if (flag) {
                for (int j = 0; j < A.size()-1; ++j) {
                    if (A[j][i] < A[j + 1][i])
                        state[j] = true;
                }
            }
        }
        return ans;
    }
};